home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / Radiant.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  6.8 KB  |  236 lines

  1. // Radiant.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Radiant.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "ChildFrm.h"
  9. #include "RadiantDoc.h"
  10. #include "RadiantView.h"
  11. #include "PrefsDlg.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CRadiantApp
  21.  
  22. BEGIN_MESSAGE_MAP(CRadiantApp, CWinApp)
  23.     //{{AFX_MSG_MAP(CRadiantApp)
  24.     ON_COMMAND(ID_HELP, OnHelp)
  25.     //}}AFX_MSG_MAP
  26.     // Standard file based document commands
  27.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  28.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  29.     // Standard print setup command
  30.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CRadiantApp construction
  35.  
  36. CRadiantApp::CRadiantApp()
  37. {
  38.     // TODO: add construction code here,
  39.     // Place all significant initialization in InitInstance
  40. }
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // The one and only CRadiantApp object
  44.  
  45. CRadiantApp theApp;
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CRadiantApp initialization
  49.  
  50. HINSTANCE g_hOpenGL32 = NULL;
  51. HINSTANCE g_hOpenGL = NULL;
  52. bool g_bBuildList = false;
  53.  
  54. BOOL CRadiantApp::InitInstance()
  55. {
  56.   //g_hOpenGL32 = ::LoadLibrary("opengl32.dll");
  57.     // AfxEnableControlContainer();
  58.  
  59.     // Standard initialization
  60.     // If you are not using these features and wish to reduce the size
  61.     //  of your final executable, you should remove from the following
  62.     //  the specific initialization routines you do not need.
  63.   //AfxEnableMemoryTracking(FALSE);
  64.  
  65. #ifdef _AFXDLL
  66.     Enable3dControls();            // Call this when using MFC in a shared DLL
  67. #else
  68.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  69. #endif
  70.  
  71.     // If there's a .INI file in the directory use it instead of registry
  72.     char RadiantPath[_MAX_PATH];
  73.     GetModuleFileName( NULL, RadiantPath, _MAX_PATH );
  74.  
  75.     // search for exe
  76.     CFileFind Finder;
  77.     Finder.FindFile( RadiantPath );
  78.     Finder.FindNextFile();
  79.     // extract root
  80.     CString Root = Finder.GetRoot();
  81.     // build root\*.ini
  82.     CString IniPath = Root + "\\REGISTRY.INI";
  83.     // search for ini file
  84.     Finder.FindNextFile();
  85.     if (Finder.FindFile( IniPath ))
  86.     {
  87.         Finder.FindNextFile();
  88.         // use the .ini file instead of the registry
  89.         free((void*)m_pszProfileName);
  90.         m_pszProfileName=_tcsdup(_T(Finder.GetFilePath()));
  91.         // look for the registry key for void* buffers storage ( these can't go into .INI files )
  92.         int i=0;
  93.         CString key;
  94.         HKEY hkResult;
  95.         DWORD dwDisp;
  96.         DWORD type;
  97.         char iBuf[3];
  98.         do
  99.         {
  100.             sprintf( iBuf, "%d", i );
  101.             key = "Software\\Q3Radiant\\IniPrefs" + CString(iBuf);
  102.             // does this key exists ?
  103.             if ( RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_ALL_ACCESS, &hkResult ) != ERROR_SUCCESS )
  104.             {
  105.                 // this key doesn't exist, so it's the one we'll use
  106.                 strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
  107.                 RegCreateKeyEx( HKEY_CURRENT_USER, key, 0, NULL, 
  108.                     REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkResult, &dwDisp );
  109.                 RegSetValueEx( hkResult, "RadiantName", 0, REG_SZ, reinterpret_cast<CONST BYTE *>(RadiantPath), strlen( RadiantPath )+1 );
  110.                 RegCloseKey( hkResult );
  111.                 break;
  112.             }
  113.             else
  114.             {
  115.                 char RadiantAux[ _MAX_PATH ];
  116.                 unsigned long size = _MAX_PATH;
  117.                 // the key exists, is it the one we are looking for ?
  118.                 RegQueryValueEx( hkResult, "RadiantName", 0, &type, reinterpret_cast<BYTE *>(RadiantAux), &size );
  119.                 RegCloseKey( hkResult );
  120.                 if ( !strcmp( RadiantAux, RadiantPath ) )
  121.                 {
  122.                     // got it !
  123.                     strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
  124.                     break;
  125.                 }
  126.             }
  127.             i++;
  128.         } while (1);
  129.         g_qeglobals.use_ini = true;
  130.     }
  131.     else
  132.     {
  133.         // Change the registry key under which our settings are stored.
  134.         // You should modify this string to be something appropriate
  135.         // such as the name of your company or organization.
  136.         SetRegistryKey("Q3Radiant");
  137.         g_qeglobals.use_ini = false;
  138.     }
  139.  
  140.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  141.  
  142.  
  143.     // Register the application's document templates.  Document templates
  144.     //  serve as the connection between documents, frame windows and views.
  145.  
  146. //    CMultiDocTemplate* pDocTemplate;
  147. //    pDocTemplate = new CMultiDocTemplate(
  148. //        IDR_RADIANTYPE,
  149. //        RUNTIME_CLASS(CRadiantDoc),
  150. //        RUNTIME_CLASS(CMainFrame), // custom MDI child frame
  151. //        RUNTIME_CLASS(CRadiantView));
  152. //    AddDocTemplate(pDocTemplate);
  153.  
  154.     // create main MDI Frame window
  155.  
  156.   g_PrefsDlg.LoadPrefs();
  157.  
  158.   int nMenu = IDR_MENU1;
  159.  
  160.   CString strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
  161.   CString strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
  162.   
  163.   if (!QGL_Init(strOpenGL, strGLU))
  164.   {
  165.     g_PrefsDlg.m_bSGIOpenGL ^= 1;
  166.     strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
  167.     strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
  168.     if (!QGL_Init(strOpenGL, strGLU))
  169.     {
  170.       AfxMessageBox("Failed to load OpenGL libraries. \"OPENGL32.DLL\" and \"OPENGL.DLL\" were tried");
  171.       return FALSE;
  172.     }
  173.     g_PrefsDlg.SavePrefs();
  174.   }
  175.  
  176.     CString strTemp = m_lpCmdLine;
  177.   strTemp.MakeLower();
  178.   if (strTemp.Find("builddefs") >= 0)
  179.     g_bBuildList = true;
  180.  
  181.     CMainFrame* pMainFrame = new CMainFrame;
  182.     if (!pMainFrame->LoadFrame(nMenu))
  183.         return FALSE;
  184.  
  185.   if (pMainFrame->m_hAccelTable)
  186.     ::DestroyAcceleratorTable(pMainFrame->m_hAccelTable);
  187.   
  188.   pMainFrame->LoadAccelTable(MAKEINTRESOURCE(IDR_MINIACCEL));
  189.  
  190.     m_pMainWnd = pMainFrame;
  191.  
  192.   // Parse command line for standard shell commands, DDE, file open
  193.     CCommandLineInfo cmdInfo;
  194.     ParseCommandLine(cmdInfo);
  195.  
  196.     // Dispatch commands specified on the command line
  197.     //if (!ProcessShellCommand(cmdInfo))
  198.     //    return FALSE;
  199.  
  200.     // The main window has been initialized, so show and update it.
  201.     pMainFrame->ShowWindow(m_nCmdShow);
  202.     pMainFrame->UpdateWindow();
  203.  
  204.   free((void*)m_pszHelpFilePath);
  205.   CString strHelp = g_strAppPath;
  206.   AddSlash(strHelp);
  207.   strHelp += "Q3RManual.chm";
  208.   m_pszHelpFilePath= _tcsdup(strHelp);
  209.  
  210.  
  211.     return TRUE;
  212. }
  213.  
  214. /////////////////////////////////////////////////////////////////////////////
  215. // CRadiantApp commands
  216.  
  217. int CRadiantApp::ExitInstance() 
  218. {
  219.     // TODO: Add your specialized code here and/or call the base class
  220.   //::FreeLibrary(g_hOpenGL32);
  221.     QGL_Shutdown();
  222.     return CWinApp::ExitInstance();
  223. }
  224.  
  225. BOOL CRadiantApp::OnIdle(LONG lCount) 
  226. {
  227.     if (g_pParentWnd)
  228.     g_pParentWnd->RoutineProcessing();
  229.     return CWinApp::OnIdle(lCount);
  230. }
  231.  
  232. void CRadiantApp::OnHelp() 
  233. {
  234.   ShellExecute(m_pMainWnd->GetSafeHwnd(), "open", m_pszHelpFilePath, NULL, NULL, SW_SHOW);
  235. }
  236.